#include <iostream>
#include <fstream>
#include <cmath>
using namespace std;
void scan(){
    const double cPi = 3.1415926535898;
    const double cDeg2Rad = cPi / 180;double momentum;
    for (int i = 0; i < 8; i++)
    {   
        
        momentum=momentum+5;
                    ofstream ofFile(Form("/home/jxm/geant4.10.06.02/desyMC _new/scan/run%d.mac",7*7*10*i + 7*7*j + 7*xi + yi), ios::trunc);
                    ofFile << "/control/verbose 0" << endl; 
                    ofFile << "/run/verbose 0" << endl; 
                    ofFile << "/vis/verbose 0" << endl; 
                    ofFile << "/process/verbose 0" << endl; 
                    ofFile << "/tracking/verbose 0" << endl; 

                    ofFile << "/MyRun/SetG4BasedFileName "
                           << "x_" << x << "y_" << y
                           << "theta_" << theta << "alpha_" << alpha << ".root" << endl;
                    
                    ofFile << "/MyGun/SimpleGun" << endl;
                    
                    ofFile << "/run/initialize" << endl;
                    ofFile << "/gun/direction " << dirX << " " << dirY << " " << dirZ << endl;
                    ofFile << "/gun/momentum 0 0 "<<x <<"GeV/c" << endl;
                    ofFile << "/gun/position " << x << " " << y << " " << 0 <<" "<<"mm"<<endl;
                    ofFile << "/gun/particle mu-" << endl;
                    ofFile << "/run/beamOn 1000" << endl;
                    
                    ofFile.close();
                }
            }
        //     ofstream ofFile(Form("run%d.mac",10 * i + j), ios::trunc);
        //     double dirX = sin(theta * cDeg2Rad) * cos(alpha *cDeg2Rad + cPi / 2);
        //     double dirY = sin(theta * cDeg2Rad) * sin(alpha *cDeg2Rad + cPi / 2);
        // double dirZ = -cos(theta * cDeg2Rad);

        // ofFile << "/gun/direction " << dirX << " " << dirY << " " << dirZ << endl;
        // ofFile << "/gun/energy 5 GeV" << endl;
        // ofFile << "/gun/postion " << "{x} {y} " << 0 << endl;
        // ofFile << "/gun/particle mu-" << endl;
        // ofFile << "/run/beamOn 1000" << endl;
        // ofFile << "/MyRun/SetG4BasedFileName "
        //        << "x_{x}y_{y}"
        //        << "theta_" << theta << "alpha" << alpha << ".root" << endl;
        // ofFile.close();
        }
    }
    return 0;
}
